package com.ruoyi.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.ExamPaperOption;
import com.ruoyi.paper.service.IExamPaperOptionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷选项实例Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/paperOption")
public class ExamPaperOptionController extends BaseController
{
    private String prefix = "jxsx/option";

    @Autowired
    private IExamPaperOptionService examPaperOptionService;

    @RequiresPermissions("jxsx:option:view")
    @GetMapping()
    public String option()
    {
        return prefix + "/option";
    }

    /**
     * 查询试卷选项实例列表
     */
    @RequiresPermissions("jxsx:option:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamPaperOption examPaperOption)
    {
        startPage();
        List<ExamPaperOption> list = examPaperOptionService.selectExamPaperOptionList(examPaperOption);
        return getDataTable(list);
    }

    /**
     * 导出试卷选项实例列表
     */
    @RequiresPermissions("jxsx:option:export")
    @Log(title = "试卷选项实例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamPaperOption examPaperOption)
    {
        List<ExamPaperOption> list = examPaperOptionService.selectExamPaperOptionList(examPaperOption);
        ExcelUtil<ExamPaperOption> util = new ExcelUtil<ExamPaperOption>(ExamPaperOption.class);
        return util.exportExcel(list, "试卷选项实例数据");
    }

    /**
     * 新增试卷选项实例
     */
    @RequiresPermissions("jxsx:option:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷选项实例
     */
    @RequiresPermissions("jxsx:option:add")
    @Log(title = "试卷选项实例", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamPaperOption examPaperOption)
    {
        return toAjax(examPaperOptionService.insertExamPaperOption(examPaperOption));
    }

    /**
     * 修改试卷选项实例
     */
    @RequiresPermissions("jxsx:option:edit")
    @GetMapping("/edit/{paperOptionId}")
    public String edit(@PathVariable("paperOptionId") String paperOptionId, ModelMap mmap)
    {
        ExamPaperOption examPaperOption = examPaperOptionService.selectExamPaperOptionByPaperOptionId(paperOptionId);
        mmap.put("examPaperOption", examPaperOption);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷选项实例
     */
    @RequiresPermissions("jxsx:option:edit")
    @Log(title = "试卷选项实例", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamPaperOption examPaperOption)
    {
        return toAjax(examPaperOptionService.updateExamPaperOption(examPaperOption));
    }

    /**
     * 删除试卷选项实例
     */
    @RequiresPermissions("jxsx:option:remove")
    @Log(title = "试卷选项实例", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examPaperOptionService.deleteExamPaperOptionByPaperOptionIds(ids));
    }
}
